package com.powernode.controller;

import com.alibaba.excel.EasyExcel;
import com.powernode.domain.Customer;
import com.powernode.service.CustomerService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.xml.crypto.Data;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/api/download")
public class DownloadController {
    @Autowired
    private CustomerService customerService;
    @GetMapping("/excel/customer")
    public void exportAllCustomerExcel(HttpServletResponse response) throws IOException {

        //查询导出的数据
        List<Customer> list = customerService.queryAllCustomerList();
        //设置响应头信息
        response.setHeader("Content-Disposition", "attachment;filename=customer.xls");
        //导出
        EasyExcel.write(response.getOutputStream(), Customer.class)
                .sheet("客户信息")
                .doWrite(list);
    }
}
